package com.ssm.base;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;
import java.util.TreeMap;

/**
 * @Author jie_ge
 * @Date 2022/4/15
 */
public class BaseController {

    /**
     * 封装分页参数及其搜索条件查询
     * @param request
     * @return
     */
    protected Map<String,Object> getFilters(HttpServletRequest request){
        Enumeration<String> paramNames = request.getParameterNames();
        Map<String, Object> filters = new TreeMap<>();
        while(paramNames != null && paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();
            String[] values = request.getParameterValues(paramName);
            if (values != null && values.length != 0) {
                if (values.length > 1) {
                    filters.put(paramName, values);
                } else {
                    filters.put(paramName, values[0]);
                }
            }
        }
        if(!filters.containsKey("pageNum")){
            filters.put("pageNum",1);
        }
        if(!filters.containsKey("pageSize")){
            filters.put("pageSize",10);
        }
        return filters;
    }
}
